package extra;

import psl.BasePage;
import extra.SQLUtil;

import java.util.HashMap;

/**
 * Created by IntelliJ IDEA.
 * User: phiteshkumar
 * Date: Feb 24, 2007
 * Time: 10:21:53 AM
 */
public class CountryList extends BasePage
{
    public String msCountryCd;
    public String msCountryName;
    public String msGroupCd;
    public String msZoneCd;
    public String msRestricted;

    public CountryList()
    {
        msViewPage = "ItemList.jsp";
        msDetailPageId = "CountryDetail";
    }

    public void setRequest(HashMap fhRequest)
    {
        super.setRequest(fhRequest);
        msCountryCd = (String)mhRequest.get("country_cd");
        msCountryName = (String)mhRequest.get("country_name");
        msGroupCd = (String)mhRequest.get("country_group_cd");
        msZoneCd = (String)mhRequest.get("zone_cd");
        msRestricted = (String)mhRequest.get("restricted");
    }

    public void performSearch()
    {
        String lsSQL =
                "Select country_cd, country_name, country_group_cd, zone_cd, restricted " +
                        "From country";

        String lsWhere = "";
        if (msCountryCd != null) lsWhere += " And country_cd = '" + msCountryCd + "'";
        if (msCountryName != null) lsWhere += " And country_name Like '" + msCountryName + "%'";
        if (msGroupCd != null) lsWhere += " And country_group_cd = '" + msGroupCd + "'";
        if (msZoneCd != null) lsWhere += " And zone_cd = '" + msZoneCd + "'";
        if (msRestricted != null) lsWhere += " And restricted = '" + msRestricted + "'";
        if (!lsWhere.equals(""))
        {
            lsWhere = " Where" + lsWhere.substring(4);
            lsSQL += lsWhere;
        }
        lsSQL += " Order By country_cd";

        mvRows = SQLUtil.retrieve(lsSQL);
    }

}
